<?php
// +----------------------------------------------------------------------
// | Bwsaas
// +----------------------------------------------------------------------
// | Copyright (c) 2015~2023 http://www.buwangyun.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Gitee ( https://gitee.com/buwangyun/bwsaas )
// +----------------------------------------------------------------------
// | Author: buwangyun <hnlg666@163.com>
// +----------------------------------------------------------------------
// | Date: 2023-06-25 10:55:00
// +----------------------------------------------------------------------

use think\migration\Migrator;
use think\migration\db\Column;

class CodeGenerateTable extends Migrator
{
    /**
     * Change Method.
     *
     * Write your reversible migrations using this method.
     *
     * More information on writing migrations is available here:
     * http://docs.phinx.org/en/latest/migrations.html#the-abstractmigration-class
     *
     * The following commands can be used in this method and Phinx will
     * automatically reverse them when rolling back:
     *
     *    createTable
     *    renameTable
     *    addColumn
     *    renameColumn
     *    addIndex
     *    addForeignKey
     *
     * Remember to call "create()" or "update()" and NOT "save()" when working
     * with the Table class.
     */
    public function change()
    {
        $table  =  $this->table('code_generate_table',['engine'=>'Innodb', 'comment' => '代码生成表信息表', 'signed' => false]);
        //迁移工具会为每个表自动创建一个自增的主键字段 id
        $table->addColumn('table_name', 'string',['comment'=>'表名称','limit'=>200,'default'=>''])
            ->addColumn('table_comment', 'string',['comment'=>'表描述','limit'=>300,'default'=>''])
            ->addColumn('template_type', 'tinyinteger', ['comment'=>'模板类型 0-单表(curd) 1-树表(curd)','limit'=>1,'default'=>0])
            ->addColumn('author', 'string',['comment'=>'作者','limit'=>100,'default'=>''])
            ->addColumn('remark', 'string',['comment'=>'备注','limit'=>255,'default'=>''])
            ->addColumn('generate_type', 'tinyinteger', ['comment'=>'生成方式  0-压缩包下载 1-生成到模块','limit'=>1,'default'=>0])
            ->addColumn('module_name', 'string',['comment'=>'模块名','limit'=>100,'default'=>''])
            ->addColumn('class_dir', 'string',['comment'=>'类目录名','limit'=>100,'default'=>''])
            ->addColumn('class_comment', 'string',['comment'=>'类描述','limit'=>100,'default'=>''])
            ->addColumn('admin_id', 'integer', ['comment'=>'管理员id','limit'=>11,'default'=>0])
            ->addColumn('menu', 'text', ['comment'=>'菜单配置','default'=>null])
            ->addColumn('delete', 'text', ['comment'=>'删除配置','default'=>null])
            ->addColumn('tree', 'text', ['comment'=>'树表配置','default'=>null])
            ->addColumn('relations', 'text', ['comment'=>'关联配置','default'=>null])
            ->addColumn('create_time', 'integer', ['comment'=>'创建时间','limit'=>11,'default'=>0])
            ->addColumn('update_time', 'integer', ['comment'=>'修改时间','limit'=>11,'default'=>0])
            //索引
            ->addIndex(['table_name'], ['unique' => true])
            //创建表
            ->create();
    }
}
